﻿using System;
using Microsoft.SPOT;
using System.Threading;
using GHIElectronics.NETMF.FEZ;

namespace LCDLiveText
{
    /// <summary>
    /// A quick/easy demo of how to use Live Text
    /// </summary>
    public class Program
    {
        static LCDLiveText liveText = LCDLiveText.Instance;
        public static void Main()
        {
            liveText.ButtonEventHandlerList.Add(new ButtonEventHandler(keyPressed));

            liveText.Print("Select to Start");
            liveText.WaitForButton(FEZ_Shields.KeypadLCD.Keys.Select, 100);
            liveText.Clear();

            liveText.Print("The first line of text taking up 40 cols");
            liveText.Print("Second line ");
            liveText.Print("Third line");
            liveText.Print("Fourth line");


            //liveText.KeyEvent += new KeyEventHandler(keyPressed);



            Thread.Sleep(Timeout.Infinite);
        }

        // This will be called whenever the list changes.
        private static bool keyPressed(object sender, ButtonEventArgs e)
        {
            switch (e.button)
            {
                case FEZ_Shields.KeypadLCD.Keys.Select:
                    if (!liveText.Flash)
                    {
                        FEZ_Shields.KeypadLCD.TurnBacklightOn(100);
                        liveText.Clear();
                        liveText.Print("OK, we are clear now");
                        liveText.Flash = true;
                    }
                    else
                    {
                        liveText.Flash = false;
                    }
                    break;

                case FEZ_Shields.KeypadLCD.Keys.Right:
                    liveText.Scroll(LCDLiveText.ScrollDirection.Right);
                    break;

                case FEZ_Shields.KeypadLCD.Keys.Left:
                    liveText.Scroll(LCDLiveText.ScrollDirection.Left);
                    break;

                case FEZ_Shields.KeypadLCD.Keys.Up:
                    liveText.Scroll(LCDLiveText.ScrollDirection.Up);
                    break;

                case FEZ_Shields.KeypadLCD.Keys.Down:
                    liveText.Scroll(LCDLiveText.ScrollDirection.Down);
                    break;

            }
            return true;
        }

    }

}
